--[[
-- Author:      feilong
-- DateTime:    2020-10-10 17:19:33
-- Description: 


--]]


local skynet = require "skynet"

local table_insert = table.insert


local MessageHandler = class("MessageHandler")

---------------------------------------------------------
-- Private
---------------------------------------------------------
function MessageHandler:ctor()


    self.client_net = new("client_net")

	self:register()	
end

--注册本服务里的消息
function MessageHandler:register()    
    g.Log():debug("i am MessageHandler register!")
    self.message_dispatch = g.MsgDis()
    self.message_dispatch:register("start", handler(self, self.start))

    self.message_dispatch:register("account.RSP_VERIFY", handler(self, self.verifyRes))
    self.message_dispatch:register("account.RSP_REGISTER_TOURIST", handler(self, self.registerTouristRes))

    self.message_dispatch:register("hall.RSP_LOGIN", handler(self, self.loginRes))
end

--注册账号
function MessageHandler:registerTourist( ... )
    
    local data = {
        matchine_token = "123",
        package_channel = "guangwang",
        os_system = "windows",
        platform = "huawei",
    }    
    self.client_net:send("account.REQ_REGISTER_TOURIST", data)   
end

---------------------------------------------------------
-- CMD
---------------------------------------------------------
function MessageHandler:start()

    --连接gate
    local ip = "127.0.0.1"
    local port = 60022
    self.client_net:connect(ip, port)


    self:registerTourist()

    -- local REQ_VERIFY = {
    --     uid = 1,
    --     key_token = "22222",
    --     package_channel = "ss",
    --     os_system = "window",
    -- }    
    -- self.client_net:send("account.REQ_VERIFY", REQ_VERIFY)   
    -- g.Log():error("_____send_data", REQ_VERIFY)    
    -- skynet.fork(function ( ... )
    --     while true do 
    --         skynet.sleep(500)    
    --         self.client_net:send("account.REQ_VERIFY", REQ_VERIFY)   
    --     end
    -- end)
end

function MessageHandler:verifyRes(msg_data)

    g.Log():error("_____verifyRes————", msg_data)   
    --验证通过，请求登录大厅
    local REQ_LOGIN = {
        device_id = "111111",          
        device_brand = "android",
        channel      = "guangwang",
        client_version = "1.0.0",
        ucode  = "0",
        os_system  = "android",       
        platform  = "huawei",
        device_token = "test",
    }
    self.client_net:send("hall.REQ_LOGIN", REQ_LOGIN)

end

function MessageHandler:registerTouristRes(msg_data)

    g.Log():error("_____registerTouristRes", msg_data)   
    --请求验证
    local REQ_VERIFY = {
        uid = msg_data.uid,
        key_token = msg_data.key_token,
        package_channel = "guangwang",
        os_system = "window",
    }    
    self.client_net:send("account.REQ_VERIFY", REQ_VERIFY)      
end


function MessageHandler:loginRes(msg_data)
    -- body
    g.Log():debug("loginRes_____", msg_data)
end


return MessageHandler